#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
Simplified BSD License (BSD)
Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this 
      list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
      this list of conditions and the following disclaimer in the documentation 
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

#region Record of Change
//             							CHANGE HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | DEVELOPER  | DESCRIPTION                                              |
// -------------------------------------------------------------------------------------
// | 08-Nov-09 | HaiNM      | First creation.                                          |
// -------------------------------------------------------------------------------------
//
#endregion

#region Record of Audit
//             							REVIEW HISTORY
// -------------------------------------------------------------------------------------
// |   DATE    | REVIEWER   | NOTES                                                    |
// -------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------
//
#endregion

#region Using directives
using System;
using System.Drawing;
using System.Drawing.Drawing2D;

using Thn;
#endregion

namespace Thn.Drawing.Painters
{
    /// <summary>
    /// Base class for 3D style painters.
    /// </summary>
#if DEBUG
    public
#else
    public
#endif
    abstract class Painter3DBase : PainterBase
    {
        #region Properties

        #region C1
        private Color mC1;
        /// <summary>
        /// Gets/Sets first color.
        /// </summary>
        public Color C1
        {
            get { return mC1; }
            set { mC1 = value; }
        }
        #endregion

        #region C2
        private Color mC2;
        /// <summary>
        /// Gets/Sets second color.
        /// </summary>
        public Color C2
        {
            get { return mC2; }
            set { mC2 = value; }
        }
        #endregion

        #endregion

        #region Paint Rectangle
        /// <summary>
        /// Paint a rectangle with
        /// </summary>
        /// <param name="canvas">The canvas to paint to.</param>
        /// <param name="r">The region where to paint in.</param>
        /// <param name="includeBorder">Whether a border should be painted.</param>
        /// <param name="includeFill">Whether inner filling should be painted.</param>
        public override void PaintRectangle(Graphics canvas, Rectangle r, bool includeBorder, bool includeFill)
        {
            #region Paint fillings

            if (includeFill)
            {
                //prepare brush
                LinearGradientBrush b = new LinearGradientBrush(r, mC1, mC2, 90f);

                //paint
                canvas.FillRectangle(b, r);

                //clean up
                b.Dispose();
            }            
            #region Defensive tracing
            else
            {
                //no need to paint
            }
            #endregion

            #endregion

            #region Paint border

            if (includeBorder)
            {
                Pen p = new Pen(mBorderColor);
                canvas.DrawRectangle(p, r);
                p.Dispose();
            }
            #region Defensive tracing
            else
            {
                //no need to paint
            }
            #endregion

            #endregion
        }
        #endregion

        #region Paint Rounded Rectangle
        /// <summary>
        /// Paint a rectangle with
        /// </summary>
        /// <param name="canvas">The canvas to paint to.</param>
        /// <param name="r">The region where to paint in.</param>
        /// <param name="includeBorder">Whether a border should be painted.</param>
        /// <param name="includeFill">Whether inner filling should be painted.</param>
        /// <param name="radius">Radius of corners.</param>
        public override void PaintRoundedRectangle(Graphics canvas, Rectangle r, bool includeBorder, bool includeFill, int radius)
        {
            #region Calculate path
            GraphicsPath path = GraphicUtils.MakeRoundedRectangle(r, true, true, true, true, radius);
            #endregion

            #region Paint fillings

            if (includeFill)
            {
                //prepare brushes
                LinearGradientBrush b = new LinearGradientBrush(r, mC1, mC2, 90f);

                //paint            
                GraphicsState state = canvas.Save();
                canvas.SetClip(path);
                canvas.FillRectangle(b, r);
                canvas.Restore(state);

                //clean up
                b.Dispose();
            }
            #region Defensive tracing
            else
            {
                //no need to paint
            }
            #endregion

            #endregion

            #region Paint border

            if (includeBorder)
            {
                Pen p = new Pen(mBorderColor);
                canvas.DrawPath(p, path);
                p.Dispose();
            }
            #region Defensive tracing
            else
            {
                //no need to paint
            }
            #endregion

            #endregion

            path.Dispose();
        }
        #endregion

        #region Paint Path
        /// <summary>
        /// Paint a graphics path.
        /// </summary>
        /// <param name="canvas">The canvas to paint to.</param>
        /// <param name="path">The path to be rendered.</param>
        /// <param name="includeBorder">Whether a border should be painted.</param>
        /// <param name="includeFill">Whether inner filling should be painted.</param>
        public override void PaintPath(Graphics canvas, GraphicsPath path, bool includeBorder, bool includeFill)
        {
            #region Paint fillings

            if (includeFill)
            {
                RectangleF r = path.GetBounds();

                //prepare brushes
                LinearGradientBrush b = new LinearGradientBrush(r, mC1, mC2, 90f);

                //paint            
                GraphicsState state = canvas.Save();
                canvas.SetClip(path);
                canvas.FillRectangle(b, r);
                canvas.Restore(state);

                //clean up
                b.Dispose();
            }
            #region Defensive tracing
            else
            {
                //no neeed to paint
            }
            #endregion

            #endregion

            #region Paint border

            if (includeBorder)
            {
                Pen p = new Pen(mBorderColor);
                canvas.DrawPath(p, path);
                p.Dispose();
            }
            #region Defensive tracing
            else
            {
                //no need to paint
            }
            #endregion

            #endregion
        }
        #endregion

        #region Constructors
        /// <summary>
        /// Default constructor.
        /// </summary>
        public Painter3DBase()
        { }
        #endregion
    }
}
